package com.dandelion.framework.enums;

/**
 * 枚举代码
 *
 * @author 77088
 * @date 2022/02/16
 */
public enum CodeEnum {

    OK(0, "ok"),
    TEST(-1, "test"),
    ERROR(1000, "error"),

    PARAM_ERROR(1001, "参数异常"),

    LOGIN_OVERDUE(1100, "登录已过期,请重新登录!"),

    UNAUTHORIZED(1101, "用户名或密码错误!"),
    FORBIDDEN(1102, "您的权限不足!"),

    LOGIN_ERROR(1103, "登录出错!"),

    USER_IS_DISABLE(1104, "用户被禁用"),
    USER_IS_LOCK(1105, "用户被锁定"),



    VERIFY_ERROR(1200, "验证码错误"),
    GET_VERIFY_CODE_TOO_MUCH(1201, "请求过于频繁,请稍后再试!"),

    USER_IS_EXIST(1300, "用户名已经存在"),
    MOBILE_IS_EXIST(1301, "手机号已经存在"),
    NICKNAME_IS_EXIST(1302, "昵称已经存在"),


    ADD_MENU_ERROR(14001, "保存菜单异常"),
    UPDATE_MENU_ERROR(14001, "修改菜单异常"),

    ADD_ROLE_ERROR(14101, "新增角色异常"),
    UPDATE_ROLE_ERROR(14102, "修改角色异常"),

    ROLE_BIND_MENU_ERROR(14102, "角色绑定资源异常"),


    ADD_USER_ERROR(14200, "新增用户异常"),
    UPDATE_USER_ERROR(14200, "修改用户异常"),

    USER_BIND_ROLE_ERROR(14300, "用户绑定角色异常"),

    ;

    private int code;

    private String msg;

    private CodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static CodeEnum getEnum(int code) {
        CodeEnum[] values = CodeEnum.values();
        for (CodeEnum codeEnum : values) {
            if (codeEnum.getCode() == code) {
                return codeEnum;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
